<?php
declare (strict_types=1);

namespace app\exam\model;

use app\common\model\BaseModel;

/**
 * 试题练习记录模型
 */
class TopicPracticeRecord extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'exam_topic_practice_record';

    /**
     * 试题类型名称获取器
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-05-26
     * @param  string $value [description]
     * @param  [type] $data  [description]
     * @return [type]        [description]
     */
    public function getQuestionTypeTextAttr($value='', $data)
    {
        $type_arr = self::getQuestionTypeArr();

        return $type_arr[$data['question_type']];
    }

    public static function getQuestionTypeArr()
    {
        return [
            1 => '单选',
            2 => '判断',
            3 => '多选',
            4 => '不定项',
            5 => '填空',
            6 => '材料',
            7 => '完形填空',
            8 => '简答题',
        ];
    }

    /**
     * 关联试题
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-02
     * @return [type] [description]
     */
    public function topic()
    {
    	return $this->belongsTo(Topic::class, 'topic_id');
    }

    /**
     * 关联试题题目名称
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-04-02
     * @return [type] [description]
     */
    public function topicTitle()
    {
        return $this->belongsTo(Topic::class, 'topic_id')->bind(['topic_title' => 'title']);
    }
}